home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / stereo / opengl / boilerplate.c next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.7 KB  |  124 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <stdio.h>
  18.  
  19. #include <Xm/Xm.h>
  20. #include <Xm/Frame.h>
  21. #include <X11/Intrinsic.h>
  22. #include <X11/extensions/SGIStereo.h>
  23.  
  24. #include <GL/gl.h>
  25. #include <GL/glu.h>
  26. #include <GL/glx.h>
  27. #include <GL/GLwMDrawA.h>
  28.  
  29. #define Color_Buffer_Size        1
  30. #define Depth_Buffer_Size        1
  31.  
  32. void                    initCB(Widget, XtPointer, XtPointer),
  33.                     exposeCB(Widget, XtPointer, XtPointer),
  34.                     resizeCB(Widget, XtPointer, XtPointer);
  35.  
  36. main(int argc, char **argv)
  37. {
  38.   XtAppContext        application_context;
  39.   Widget        toplevel, glw;
  40.   Arg            args[10];
  41.   int             n = 0;
  42.   GLXContext        glw_context;
  43.   String         fallback[] = {
  44.                           "*frame*shadowType: SHADOW_IN",
  45.                       "*boiler*width: 400",
  46.                       "*boiler*height: 400",
  47.                       NULL
  48.                       };
  49.   
  50.   toplevel = XtAppInitialize(&application_context, "BoilerPlate",
  51.                  (XrmOptionDescList) NULL, 0,
  52.                  &argc, (String *)argv,
  53.                  fallback, (ArgList)NULL, 0);
  54.  
  55.   n=0;
  56.   XtSetArg(args[n], GLwNrgba, TRUE); n++;
  57.   XtSetArg(args[n], GLwNdoublebuffer, TRUE); n++;
  58.   XtSetArg(args[n], GLwNredSize, Color_Buffer_Size); n++;
  59.   XtSetArg(args[n], GLwNgreenSize, Color_Buffer_Size); n++;
  60.   XtSetArg(args[n], GLwNblueSize, Color_Buffer_Size); n++;
  61.   XtSetArg(args[n], GLwCDepthSize, Depth_Buffer_Size); n++;
  62.  
  63.   glw = XtCreateWidget("boiler", glwMDrawingAreaWidgetClass, 
  64.                toplevel, args, n);
  65.   
  66.   XtAddCallback(glw, GLwNginitCallback, initCB, &glw_context);
  67.   XtAddCallback(glw, GLwNexposeCallback, exposeCB, &glw_context);
  68.   XtAddCallback(glw, GLwNresizeCallback, resizeCB, &glw_context);
  69.   XtManageChild(glw);
  70.   
  71.   XtRealizeWidget(toplevel);
  72.   XtAppMainLoop(application_context);
  73. }
  74.  
  75. void 
  76. initCB(Widget w, XtPointer client_data, XtPointer call_data)
  77. {
  78.   Display    *display = XtDisplay(w);
  79.   int        screen = DefaultScreen(display);
  80.   Window    window = XtWindow(w);
  81.   XVisualInfo    *vi;
  82.   GLXContext    *glw_context = (GLXContext *) client_data;
  83.   Arg        args[10];
  84.  
  85.   XtSetArg(args[0], GLwNvisualInfo, &vi);
  86.   XtGetValues(w, args, 1);
  87.   
  88.   *glw_context = glXCreateContext(display, vi, None, GL_TRUE);
  89.   glXMakeCurrent(display, window, *glw_context);
  90.  
  91.   glClearColor(0.0, 0.0, 0.0, 1.0);
  92.   glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
  93.   glXSwapBuffers(display, window);
  94.   glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
  95.  
  96. }
  97.  
  98. void
  99. exposeCB(Widget w, XtPointer client_data, XtPointer call_data)
  100. {
  101.   Display       *display = XtDisplay(w);
  102.   Window    window = XtWindow(w);
  103.   GLXContext    *glw_context = (GLXContext *) client_data;
  104.  
  105.   glXMakeCurrent(display, window, *glw_context);
  106.   glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
  107.   glXSwapBuffers(display, window);
  108.   glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
  109.   
  110. }
  111.  
  112. void
  113. resizeCB(Widget w, XtPointer client_data, XtPointer call_data)
  114. {
  115.   Display       *display = XtDisplay(w);
  116.   Window        window = XtWindow(w);
  117.   GLXContext    *glw_context = (GLXContext *) client_data;
  118.   
  119.   glXMakeCurrent(display, window, *glw_context);
  120.   glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
  121.   glXSwapBuffers(display, window);
  122.   glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
  123. }
  124.